import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* 布局
 * Layout 是已经设置好的基本布局，包括顶部导航，侧边栏，通知栏，主页面<app-main>
 * 如果有新的页面布局要求，可以另外创建布局文件 放置在@/views/layout/Layout下
 */
import Layout from '@/views/layout/Layout'

/** note: submenu only apppear when children.length>=1
**/

/**
* hidden: true                   如果 `hidden:true` 该菜单将不会显示在侧边栏 (default is false)
* alwaysShow: true               如果设置为 true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             name字段用于 <keep-alive> (必须设置!!!)
* meta : {
    roles: ['admin','editor']    控制页面的访问权限 (可以设置多个)
    title: 'title'               显示在侧边栏和面包屑中的标题 (recommend set)
    icon: 'svg-name'             侧边栏显示的图标,
    noCache: true                如果设置为 true，页面将不会被缓存(default is false)
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/authredirect', component: () => import('@/views/login/authredirect'), hidden: true },
  { path: '/404', component: () => import('@/views/errorPage/404'), hidden: true },
  { path: '/401', component: () => import('@/views/errorPage/401'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'dashboard',
      meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
    }]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  { path: '*', redirect: '/404', hidden: true },
  {
    path: '/admin/account',
    component: Layout,
    redirect: 'noredirect',
    meta: { title: 'account', icon: 'user', roles: ['admin', 'supervisor'] },
    children: [{
      path: 'user',
      component: () => import('@/views/admin/user'),
      name: 'account',
      meta: { title: 'account', icon: 'user', noCache: true }
    }, {
      path: 'role',
      component: () => import('@/views/admin/role'),
      name: 'role',
      meta: { title: 'role', icon: 'peoples', noCache: true }
    }]
  },
  {
    path: '/admin/safeguard',
    component: Layout,
    redirect: 'noredirect',
    meta: { title: 'safeguard', icon: 'system-monitor', roles: ['admin', 'supervisor'] },
    children: [{
      path: 'druid',
      component: () => import('@/views/admin/safeguard/druid'),
      name: 'druid',
      meta: { title: 'druid', icon: 'database' }
    },
    {
      path: 'swagger',
      component: () => import('@/views/admin/safeguard/swagger'),
      name: 'swagger',
      meta: { title: 'swagger', icon: 'documentation' }
    },
    {
      path: 'monitor',
      component: () => import('@/views/admin/safeguard/monitor'),
      name: 'monitor',
      meta: { title: 'monitor', icon: 'pie chart' }
    }]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/list',
    name: 'example',
    meta: { title: 'example', icon: 'example', roles: ['admin', 'supervisor'] },
    children: [
      { path: 'index', component: () => import('@/views/example/demo/index'), name: 'demo', meta: { title: 'demo', icon: 'star', noCache: true }},
      { path: 'create', component: () => import('@/views/example/create'), name: 'createArticle', meta: { title: 'createArticle', icon: 'edit' }},
      { path: 'edit/:id(\\d+)', component: () => import('@/views/example/edit'), name: 'editArticle', meta: { title: 'editArticle', noCache: true }, hidden: true },
      { path: 'list', component: () => import('@/views/example/list'), name: 'articleList', meta: { title: 'articleList', icon: 'list' }},
      { path: 'guide', component: () => import('@/views/example/guide/index'), name: 'guide', meta: { title: 'guide', icon: 'guide', noCache: true }},
      { path: 'tab', component: () => import('@/views/example/tab/index'), name: 'tab', meta: { title: 'tab', icon: 'tab' }},
      { path: 'icons', component: () => import('@/views/example/svg-icons/index'), name: 'icons', meta: { title: 'icons', icon: 'icon', noCache: true }},
      // 表格
      { path: 'dynamic-table', component: () => import('@/views/example/table/dynamicTable/index'), name: 'dynamicTable', meta: { title: 'dynamicTable', icon: 'table', noCache: true }},
      { path: 'drag-table', component: () => import('@/views/example/table/dragTable'), name: 'dragTable', meta: { title: 'dragTable', icon: 'table', noCache: true }},
      { path: 'inline-edit-table', component: () => import('@/views/example/table/inlineEditTable'), name: 'inlineEditTable', meta: { title: 'inlineEditTable', icon: 'table', noCache: true }},
      { path: 'tree-table', component: () => import('@/views/example/table/treeTable/treeTable'), name: 'treeTableDemo', meta: { title: 'treeTable', icon: 'table', noCache: true }},
      { path: 'custom-tree-table', component: () => import('@/views/example/table/treeTable/customTreeTable'), name: 'customTreeTableDemo', meta: { title: 'customTreeTable', icon: 'table', noCache: true }},
      { path: 'complex-table', component: () => import('@/views/example/table/complexTable'), name: 'complexTable', meta: { title: 'complexTable', icon: 'table', noCache: true }},
      // 组件
      { path: 'tinymce', component: () => import('@/views/example/components-demo/tinymce'), name: 'tinymce-demo', meta: { title: 'tinymce', icon: 'component' }},
      { path: 'markdown', component: () => import('@/views/example/components-demo/markdown'), name: 'markdown-demo', meta: { title: 'markdown', icon: 'component' }},
      { path: 'json-editor', component: () => import('@/views/example/components-demo/jsonEditor'), name: 'jsonEditor-demo', meta: { title: 'jsonEditor', icon: 'component' }},
      { path: 'splitpane', component: () => import('@/views/example/components-demo/splitpane'), name: 'splitpane-demo', meta: { title: 'splitPane', icon: 'component' }},
      { path: 'avatar-upload', component: () => import('@/views/example/components-demo/avatarUpload'), name: 'avatarUpload-demo', meta: { title: 'avatarUpload', icon: 'component' }},
      { path: 'dropzone', component: () => import('@/views/example/components-demo/dropzone'), name: 'dropzone-demo', meta: { title: 'dropzone', icon: 'component' }},
      { path: 'sticky', component: () => import('@/views/example/components-demo/sticky'), name: 'sticky-demo', meta: { title: 'sticky', icon: 'component' }},
      { path: 'count-to', component: () => import('@/views/example/components-demo/countTo'), name: 'countTo-demo', meta: { title: 'countTo', icon: 'component' }},
      { path: 'mixin', component: () => import('@/views/example/components-demo/mixin'), name: 'componentMixin-demo', meta: { title: 'componentMixin', icon: 'component' }},
      { path: 'back-to-top', component: () => import('@/views/example/components-demo/backToTop'), name: 'backToTop-demo', meta: { title: 'backToTop', icon: 'component' }},
      { path: 'drag-dialog', component: () => import('@/views/example/components-demo/dragDialog'), name: 'dragDialog-demo', meta: { title: 'dragDialog', icon: 'component' }},
      { path: 'dnd-list', component: () => import('@/views/example/components-demo/dndList'), name: 'dndList-demo', meta: { title: 'dndList', icon: 'component' }},
      { path: 'drag-kanban', component: () => import('@/views/example/components-demo/dragKanban'), name: 'dragKanban-demo', meta: { title: 'dragKanban', icon: 'component' }},
      // 图表
      { path: 'keyboard', component: () => import('@/views/example/charts/keyboard'), name: 'keyboardChart', meta: { title: 'keyboardChart', icon: 'chart', noCache: true }},
      { path: 'line', component: () => import('@/views/example/charts/line'), name: 'lineChart', meta: { title: 'lineChart', icon: 'chart', noCache: true }},
      { path: 'mixchart', component: () => import('@/views/example/charts/mixChart'), name: 'mixChart', meta: { title: 'mixChart', icon: 'chart', noCache: true }},
      // excel 导出
      { path: 'export-excel', component: () => import('@/views/example/excel/exportExcel'), name: 'exportExcel', meta: { title: 'exportExcel', icon: 'excel' }},
      { path: 'export-selected-excel', component: () => import('@/views/example/excel/selectExcel'), name: 'selectExcel', meta: { title: 'selectExcel', icon: 'excel' }},
      { path: 'upload-excel', component: () => import('@/views/example/excel/uploadExcel'), name: 'uploadExcel', meta: { title: 'uploadExcel', icon: 'excel' }},
      { path: 'download', component: () => import('@/views/example/zip/index'), name: 'exportZip', meta: { title: 'exportZip', icon: 'zip' }},
      // 主题
      { path: 'theme', component: () => import('@/views/example/theme/index'), name: 'theme', meta: { title: 'theme', icon: 'theme' }},
      // 剪贴板
      { path: 'clipboard', component: () => import('@/views/example/clipboard/index'), name: 'clipboardDemo', meta: { title: 'clipboardDemo', icon: 'clipboard' }},
      // 国际化
      { path: 'i18n-demo', component: () => import('@/views/example/i18n-demo/index'), name: 'i18n', meta: { title: 'i18n', icon: 'international' }}
    ]
  }
]
